/**
 * OPBillTableModel.java
 * @author pkendzo
 * Email: pkendzo@msn.com
 * 2010
 */
package lu.med.praxiswahl.wahlumed.client.rechnungen.op.model;

import javax.swing.table.AbstractTableModel;

public class OPBillTableModel extends AbstractTableModel
{

    /**
     * 
     */
    private static final long serialVersionUID = 4872790582021326093L;

    private OPBillDataset data;

    private int selected = -1;

    /**
     * 
     */
    public OPBillTableModel(OPBillDataset data)
    {
	this.data = data;
    }

    /*
     * (non-Javadoc)
     * 
     * @see javax.swing.table.TableModel#getColumnCount()
     */
    @Override
    public int getColumnCount()
    {
	// TODO Auto-generated method stub
	return 9;
    }

    /*
     * (non-Javadoc)
     * 
     * @see javax.swing.table.TableModel#getRowCount()
     */
    @Override
    public int getRowCount()
    {
	// TODO Auto-generated method stub
	return 10;
    }

    /*
     * (non-Javadoc)
     * 
     * @see javax.swing.table.TableModel#getValueAt(int, int)
     */
    @Override
    public Object getValueAt(int row, int column)
    {
	if (data == null)
	{
	    return "";
	}
	return data.getDataRow()[row][column];
    }

    @Override
    public String getColumnName(int columnIndex)
    {
	switch (columnIndex)
	{
	case 0:
	    return "H";
	case 1:
	    return "MED";
	case 2:
	    return "DATE(DU-AU)/DENT/HEURE";
	case 3:
	    return "CODE TARIF/LIBELLE/OBJET";
	case 4:
	    return "NBR";
	case 5:
	    return "MONTANT";
	case 6:
	    return "MED.PRES.";
	case 7:
	    return "ABRECHNUNGSCODE.";
	case 8:
	    return "BASIS";

	}
	return "";
    }

    public int getFirstVoidRow()
    {
	// TODO Auto-generated method stub
	return 0;
    }

    public boolean isDrawDate(int row)
    {
	/*
	 * Das Datum muss eingezeichnet werden
	 */
	if (row > 0)
	{
	    String checkDate = "";

	    checkDate = data.getDataRow()[row - 1][2];
	    /*
	     * Ist der vorherige Eintrag gleich dem aktuellen ?
	     */
	    if (checkDate.equals(data.getDataRow()[row][2]))
		return false;
	}
	return true;
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex)
    {
	return true;
    }

    @Override
    public void setValueAt(Object d, int row, int column)
    {
	if (data == null)
	{
	    return;
	}

	data.setDataRow((String) d, row, column);

	this.fireTableDataChanged();
    }

    /**
     * @return the data
     */
    public OPBillDataset getData()
    {
	return data;
    }

    /**
     * @param data
     *            the data to set
     */
    public void setData(OPBillDataset data)
    {
	this.data = data;
    }

    public void setSelected(int c)
    {
	selected = c;
    }

    public int getSelected()
    {
	return selected;
    }

}
